﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ExcelExport
{
    public class Debug
    {
        private static StringBuilder sCachedStringBuilder = new StringBuilder();
        public static void Log(object message)
        {
            if (Util.isShowLog)
                Console.WriteLine(message.ToString());
        }
        public static void Log(object message, params object[] arg)
        {
            if (Util.isShowLog)
                Console.WriteLine(Format(message.ToString(), arg));
        }
        //错误信息不受控制，都要显示
        public static void Error(object message)
        {
            Console.WriteLine(message.ToString());
        }
        public static void Error(object message, params object[] arg)
        {
            Console.WriteLine(Format(message.ToString(), arg));
        }

        public static string Format(string format, params object[] args)
        {
            lock (sCachedStringBuilder)
            {
                if (format == null)
                {
                    throw new Exception("Format is invalid.");
                }

                if (args == null)
                {
                    throw new Exception("Args is invalid.");
                }

                sCachedStringBuilder.Length = 0;
                sCachedStringBuilder.AppendFormat(format, args);
                return sCachedStringBuilder.ToString();
            }
        }
        public static string Format(string format, object arg0, object arg1)
        {
            lock (sCachedStringBuilder)
            {
                if (format == null)
                {
                    throw new Exception("Format is invalid.");
                }

                sCachedStringBuilder.Length = 0;
                sCachedStringBuilder.AppendFormat(format, arg0, arg1);
                return sCachedStringBuilder.ToString();
            }
        }
        public static string Format(string format, object arg0)
        {
            lock (sCachedStringBuilder)
            {
                if (format == null)
                {
                    throw new Exception("Format is invalid.");
                }

                sCachedStringBuilder.Length = 0;
                sCachedStringBuilder.AppendFormat(format, arg0);
                return sCachedStringBuilder.ToString();
            }
        }
        public static string Format(string format, object arg0, object arg1, object arg2)
        {
            lock (sCachedStringBuilder)
            {
                if (format == null)
                {
                    throw new Exception("Format is invalid.");
                }

                sCachedStringBuilder.Length = 0;
                sCachedStringBuilder.AppendFormat(format, arg0, arg1, arg2);
                return sCachedStringBuilder.ToString();
            }
        }
    }
}
